﻿using System;
using WF_AppFuel.Validation.Base;

namespace WF_AppFuel.Validation.Engines
{
    /// <summary>
    /// This engine is used for validating URL fields
    /// </summary>
    /// <author>Dennis Q. Pitallano</author>
    /// <author>Arjay C. Nacion</author>
    public sealed class IsURLValidationEngine : BaseValidationEngine
    {
        public override bool Run()
        {
            if (Value == null)
                return false;

            if (string.IsNullOrEmpty(Value.ToString().Trim()))
                return false;

            if (Uri.IsWellFormedUriString(Value.ToString(), 
                UriKind.RelativeOrAbsolute))
            {
                Uri tempUri = null;
                bool isURI = Uri.TryCreate(Value.ToString(), 
                    UriKind.RelativeOrAbsolute, out tempUri);

                if (!isURI)
                    return false;
            }

            return true;
        }
    }
}
